package com.ysr.controller;

import com.ysr.pojo.PayMent;
import com.ysr.result.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;

@RestController
@RequestMapping(value = "consumer")
@Slf4j
public class OrderController {

    //调用支付订单服务端的ip+端口号
    public static final  String PAYMENT_URL = "http://ysr-payment";

    @Autowired
    private RestTemplate restTemplate;
    //创建支付订单的接口
    @PostMapping("/payment/create")
    public CommonResult<PayMent> create(PayMent payMent){
        return restTemplate.postForObject(PAYMENT_URL+"/payment/create",payMent, CommonResult.class);
    }
    //获取id获取支付订单
    @GetMapping("/payment/get/{id}")
    public CommonResult<PayMent> getPayment(@PathVariable("id") Long id){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/get/"+id,CommonResult.class);
    }

    //创建支付订单的接口
    @PostMapping("/payment/add")
    public CommonResult<PayMent> add(PayMent payMent){
        return restTemplate.postForObject(PAYMENT_URL+"/payment/add",payMent, CommonResult.class);
    }

    //获取id获取支付订单
    @GetMapping("/payment/queryPayMentById")
    public CommonResult<PayMent> queryPayMentById(Long id){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/queryPayMentById?id="+id,CommonResult.class);
    }

}
